'use strict'
const Controller = require('egg').Controller;
const svgCaptcha = require('svg-captcha');

class CaptchaController extends Controller 
{
    async captcha() {
        const captcha = svgCaptcha.create({
          size: 4,              //图片验证码的字符数
          fontSize: 50,
          ignoreChars: 'Ooli',    //忽略的一些字符
          width: 80,
          height: 29,
          noise: 2,
          color: true,
          background: '#eee'
        });
        this.ctx.session.verify = captcha.text;       //text及data都是函数返回的string属性的对象  将图片验证码中的text传到session里边 
        this.ctx.response.type = 'image/svg+xml';     //返回的类型
        this.ctx.body = captcha.data;                //返回一张图片
      }
}
module.exports = CaptchaController;
